package com.zk.user.controller;

import com.zk.common.entity.R;
import com.zk.user.entity.User;
import com.zk.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户表 前端控制器
 * </p>
 *
 * @author hbxfwf
 * @since 2023-05-14
 */
@RestController
@RequestMapping("/user/user")
public class UserController {

	@Autowired
	private UserService userService;
	@Value("${server.port}")
	private int port;
	//1. 列表所有用户
	@GetMapping("list")
	public R list(){
		List<User> list = userService.list();
		return R.ok().data("list",list).data("port",port);
	}

	//2. 根据用户id查询单个用户
	@GetMapping("/findById/{id}")
	public R findById(@PathVariable String id){
		User user = userService.getById(id);
		return R.ok().data("user",user);
	}
}
